//****************************************************************
//* Copyright (c) 2008 Ford Motor Company. All Rights Reserved.
//*
//* $$Workfile:   CostStructureDefForm.java  $$
//* $$Revision:   1.4  $$
//* $$Author:   TMALDON4  $$
//* $$Date:   Dec 15 2008 07:01:58  $$
//*
//*****************************************************************
package ar.com.ford.it.fullEconomics.view.form;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Collection;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Stack;
import javax.servlet.http.HttpServletRequest;
import org.apache.commons.lang.StringUtils;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.util.MessageResources;
import org.apache.struts.validator.ValidatorForm;
import ar.com.ford.it.fullEconomics.persistence.dto.Ncas012VehicleVw;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesc02Coststvers;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesc03Subcoststr;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesc07Subcstitem;
import ar.com.ford.it.fullEconomics.persistence.dto.Teesp01Part;
import ar.com.ford.it.fullEconomics.util.FullEconomicsDateUtil;

public class CostStructureDefForm extends ValidatorForm {
    private String section;
    private String tierNumberTitle;
    private String csNumber;
    private String csVersion;
    private String supplierType;
    private String supplierCode;
    private String supplierName;
    private String csType;
    private String commodityName;
    private String partClass;
    private String partPrefix;
    private String partBase;
    private String partSuffix;
    private String tier;
    private String componentPath;
    private String createdBy;
    private String createdDate;
    private String proposedBy;
    private String proposedDate;
    private String approvedBy;
    private String approvedDate;
    private String itemCategorySel;
    private Collection itemCategoriesCol;
    private String itemSel;
    private Collection itemsCol;
    private String economicIndexSel;
    private Collection economicIndexesCol;
    private String compItem;
    private String subCsName;
    private String compSubCs;
    private String total;
    private Collection<Teesc07Subcstitem> subCSItems;
    private Collection<Teesc07Subcstitem> subCSItemsNV;
    private Collection<Teesc03Subcoststr> subCostStructures;
    private Teesc02Coststvers costStructureVersion;
    private Teesc07Subcstitem subCostStrItemSelected;
    private Teesc07Subcstitem subCostStrItemNVSelected;
    private Teesc03Subcoststr subCostStrSelected;
    private Stack<Teesc03Subcoststr> hierarchy;
    private String enableComboEconomicIndex;
    private String vehicleLineSel;
    private String evolveFromSel;
    private String evolveToSel;
    private String evolveFromYear;
    private String evolveToYear; 
    private String evolveFromTemp;
    private String evolveToTemp;
    private String evolveFromYearTemp;
    private String evolveToYearTemp; 
    private String evolveFromType;
    private String evolveToType;
    private String mixDate;
    private String mixYear;
    private String activacionNiveles;
    private Map<Teesc03Subcoststr, Collection<Teesc07Subcstitem>> mapaNodosNiveles;
    private String campoVacioAux = "";
    
    public void resetForm() {
        this.section = null;
        this.tierNumberTitle = null;
        this.csNumber = null;
        this.csVersion = null;
        this.supplierType = null;
        this.supplierCode = null;
        this.supplierName = null;
        this.csType = null;
        this.commodityName = null;
        this.partClass = null;
        this.partPrefix = null;
        this.partBase = null;
        this.partSuffix = null;
        this.tier = null;
        this.componentPath = null;
        this.createdBy = null;
        this.createdDate = null;
        this.proposedBy = null;
        this.proposedDate = null;
        this.approvedBy = null;
        this.approvedDate = null;
        this.itemCategorySel = null;
        this.itemCategoriesCol = null;
        this.itemSel = null;
        this.itemsCol = null;
        this.economicIndexSel = null;
        this.economicIndexesCol = null;
        this.compItem = null;
        this.subCsName = null;
        this.compSubCs = null;
        this.total = null;
        this.subCSItems = null;
        this.subCSItemsNV = null;
        this.subCostStructures = null;
        this.costStructureVersion = null;
        this.subCostStrItemSelected = null;
        this.subCostStrItemNVSelected = null;
        this.subCostStrSelected = null;
        this.hierarchy = new Stack<Teesc03Subcoststr>();
        this.enableComboEconomicIndex = null;
        this.vehicleLineSel = null;
        this.evolveFromSel = null;
        this.evolveToSel = null;
        this.evolveFromYear = null;
        this.evolveToYear = null;        
        this.mixDate = null;
        this.mapaNodosNiveles = new HashMap<Teesc03Subcoststr, Collection<Teesc07Subcstitem>>();
    }

    public void setDetails() {
        Teesp01Part part = null;
        Calendar aux = new GregorianCalendar();
        String componentPath = "";

        this.setCsNumber(costStructureVersion.getTeesc01Coststruct()
                .getEesc01CststrNumberK().toString());
        this.setCsVersion(costStructureVersion.getEesc02CststvVersionNumberK()
                .toString());
        this.setSupplierType(costStructureVersion.getTeesc01Coststruct()
                .getTeess01Supplier().getEess01SupplierClassCodeC());
        this.setSupplierCode(costStructureVersion.getTeesc01Coststruct()
                .getTeess01Supplier().getEess01SupplierCodeC());
        this.setSupplierName(costStructureVersion.getTeesc01Coststruct()
                .getTeess01Supplier().getEess01SupplierNameN());
        this.setCsType(costStructureVersion.getTeesc01Coststruct()
                .getEesc01CststrTypeCodeC());
        if (this.getCsType().equals("C")) {
            this.setCommodityName(costStructureVersion.getTeesc01Coststruct()
                    .getTeesp02Commodity().getEesp02CommodityNameN());
        } else if (this.getCsType().equals("P")) {
            part = costStructureVersion.getTeesc01Coststruct()
                    .getTeesp04Supply().getTeesp01Part();
            this.setPartClass(part.getEesp01PartClassCodeC());
            this.setPartPrefix(part.getEesp01PartPrefixCodeC());
            this.setPartBase(part.getEesp01PartBaseCodeC());
            this.setPartSuffix(part.getEesp01PartSuffixCodeC());
        }
        this.setCreatedBy(costStructureVersion.getEesc02CreateUserC());
        this.setProposedBy(costStructureVersion.getEesc02CststvProposalUserC());
        this.setApprovedBy(costStructureVersion.getEesc02CststvApprovalUserC());

        if (costStructureVersion.getEesc02CreateS() != null) {
            aux.setTimeInMillis(costStructureVersion.getEesc02CreateS()
                    .getTime());
            this.setCreatedDate(FullEconomicsDateUtil.format(aux));
        }
        if (costStructureVersion.getEesc02CststvProposalS() != null) {
            aux.setTimeInMillis(costStructureVersion.getEesc02CststvProposalS()
                    .getTime());
            this.setProposedDate(FullEconomicsDateUtil.format(aux));
        }
        if (costStructureVersion.getEesc02CststvApprovalS() != null) {
            aux.setTimeInMillis(costStructureVersion.getEesc02CststvApprovalS()
                    .getTime());
            this.setApprovedDate(FullEconomicsDateUtil.format(aux));
        }

        this.setTier(String.valueOf(hierarchy.size()));

        // El tier de la subCostructure es siempre tier + 1
        this.setTierNumberTitle(String.valueOf(Integer.parseInt(tier) + 1));

        for (int i = 0; i < hierarchy.size(); i++) {
            componentPath += hierarchy.get(i).getEesc03SubcstNameN();
            if (i < hierarchy.size() - 1) {
                componentPath += " >> ";
            }
        }
        this.setComponentPath(componentPath);
    }

    public void clearCreateUpdateFields() {
        this.setSubCostStrSelected(null);
        this.setSubCostStrItemSelected(null);
        this.setSubCostStrItemNVSelected(null);
        this.setCompItem(null);
        this.setCompSubCs(null);
        this.setSubCsName(null);
        this.setEconomicIndexSel("-1");
        this.setItemSel("-1");
        this.setEnableComboEconomicIndex(null);
        this.setItemCategorySel("-1");
    }

    public void clearSubCostStrCreateUpdateFields() {
        this.setSubCostStrSelected(null);
        this.setCompSubCs(null);
        this.setSubCsName(null);
    }

    public void clearSubCostStrItemCreateUpdateFields() {
        this.setSubCostStrItemSelected(null);
        this.setSubCostStrItemNVSelected(null);
        this.setCompItem(null);
        this.setEconomicIndexSel("-1");
        this.setItemSel("-1");
        this.setEnableComboEconomicIndex(null);
        this.setItemCategorySel("-1");
    }

    public Teesc07Subcstitem getSubCostStrItemNVSelected() {
        return subCostStrItemNVSelected;
    }

    public void setSubCostStrItemNVSelected(
                                            Teesc07Subcstitem subCostStrItemNVSelected) {
        this.subCostStrItemNVSelected = subCostStrItemNVSelected;
    }

    public Teesc07Subcstitem getSubCostStrItemSelected() {
        return subCostStrItemSelected;
    }

    public void setSubCostStrItemSelected(
                                          Teesc07Subcstitem subCostStrItemSelected) {
        this.subCostStrItemSelected = subCostStrItemSelected;
    }

    public Teesc03Subcoststr getSubCostStrSelected() {
        return subCostStrSelected;
    }

    public void setSubCostStrSelected(Teesc03Subcoststr subCostStrSelected) {
        this.subCostStrSelected = subCostStrSelected;
    }

    public Teesc02Coststvers getCostStructureVersion() {
        return costStructureVersion;
    }

    public void setCostStructureVersion(Teesc02Coststvers costStructureVersion) {
        this.costStructureVersion = costStructureVersion;
    }

    public String getApprovedBy() {
        return approvedBy;
    }

    public void setApprovedBy(String approvedBy) {
        this.approvedBy = approvedBy;
    }

    public String getApprovedDate() {
        return approvedDate;
    }

    public void setApprovedDate(String approvedDate) {
        this.approvedDate = approvedDate;
    }

    public String getCommodityName() {
        return commodityName;
    }

    public void setCommodityName(String commodityName) {
        this.commodityName = commodityName;
    }

    public String getCompItem() {
        return compItem;
    }

    public void setCompItem(String compItem) {
        this.compItem = compItem;
    }

    public String getComponentPath() {
        return componentPath;
    }

    public void setComponentPath(String componentPath) {
        this.componentPath = componentPath;
    }

    public String getCompSubCs() {
        return compSubCs;
    }

    public void setCompSubCs(String compSubCs) {
        this.compSubCs = compSubCs;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public String getCreatedDate() {
        return createdDate;
    }

    public void setCreatedDate(String createdDate) {
        this.createdDate = createdDate;
    }

    public String getCsNumber() {
        return csNumber;
    }

    public void setCsNumber(String csNumber) {
        this.csNumber = csNumber;
    }

    public String getCsType() {
        return csType;
    }

    public void setCsType(String csType) {
        this.csType = csType;
    }

    public String getCsVersion() {
        return csVersion;
    }

    public void setCsVersion(String csVersion) {
        this.csVersion = csVersion;
    }

    public Collection getEconomicIndexesCol() {
        return economicIndexesCol;
    }

    public void setEconomicIndexesCol(Collection economicIndexesCol) {
        this.economicIndexesCol = economicIndexesCol;
    }

    public String getEconomicIndexSel() {
        return economicIndexSel;
    }

    public void setEconomicIndexSel(String economicIndexSel) {
        this.economicIndexSel = economicIndexSel;
    }

    public Collection getItemCategoriesCol() {
        return itemCategoriesCol;
    }

    public void setItemCategoriesCol(Collection itemCategoriesCol) {
        this.itemCategoriesCol = itemCategoriesCol;
    }

    public String getItemCategorySel() {
        return itemCategorySel;
    }

    public void setItemCategorySel(String itemCategorySel) {
        this.itemCategorySel = itemCategorySel;
    }

    public Collection getItemsCol() {
        return itemsCol;
    }

    public void setItemsCol(Collection itemsCol) {
        this.itemsCol = itemsCol;
    }

    public String getItemSel() {
        return itemSel;
    }

    public void setItemSel(String itemSel) {
        this.itemSel = itemSel;
    }

    public String getPartBase() {
        return partBase;
    }

    public void setPartBase(String partBase) {
        this.partBase = partBase;
    }

    public String getPartClass() {
        return partClass;
    }

    public void setPartClass(String partClass) {
        this.partClass = partClass;
    }

    public String getPartPrefix() {
        return partPrefix;
    }

    public void setPartPrefix(String partPrefix) {
        this.partPrefix = partPrefix;
    }

    public String getPartSuffix() {
        return partSuffix;
    }

    public void setPartSuffix(String partSuffix) {
        this.partSuffix = partSuffix;
    }

    public String getProposedBy() {
        return proposedBy;
    }

    public void setProposedBy(String proposedBy) {
        this.proposedBy = proposedBy;
    }

    public String getProposedDate() {
        return proposedDate;
    }

    public void setProposedDate(String proposedDate) {
        this.proposedDate = proposedDate;
    }

    public String getSection() {
        return section;
    }

    public void setSection(String section) {
        this.section = section;
    }

    public String getSubCsName() {
        return subCsName;
    }

    public void setSubCsName(String subCsName) {
        this.subCsName = subCsName;
    }

    public String getSupplierCode() {
        return supplierCode;
    }

    public void setSupplierCode(String supplierCode) {
        this.supplierCode = supplierCode;
    }

    public String getSupplierName() {
        return supplierName;
    }

    public void setSupplierName(String supplierName) {
        this.supplierName = supplierName;
    }

    public String getSupplierType() {
        return supplierType;
    }

    public void setSupplierType(String supplierType) {
        this.supplierType = supplierType;
    }

    public String getTier() {
        return tier;
    }

    public void setTier(String tier) {
        this.tier = tier;
    }

    public String getTierNumberTitle() {
        return tierNumberTitle;
    }

    public void setTierNumberTitle(String tierNumberTitle) {
        this.tierNumberTitle = tierNumberTitle;
    }

    public String getTotal() {
        return total;
    }

    public void setTotal(String total) {
        this.total = total;
    }

    public Collection<Teesc03Subcoststr> getSubCostStructures() {
        return subCostStructures;
    }

    public void setSubCostStructures(
                                     Collection<Teesc03Subcoststr> subCostStructures) {
        this.subCostStructures = subCostStructures;
    }

    public Collection<Teesc07Subcstitem> getSubCSItems() {
        return subCSItems;
    }

    public Collection<Teesc07Subcstitem> getSubCSItemsNV() {
        return subCSItemsNV;
    }

    public void setSubCSItems(Collection<Teesc07Subcstitem> subCSItems) {
        this.subCSItems = subCSItems;
    }

    public void setSubCSItemsNV(Collection<Teesc07Subcstitem> subCSItemsNV) {
        this.subCSItemsNV = subCSItemsNV;
    }

    public void setSubCSItemMapped(String key, String value) {
        List<Teesc07Subcstitem> subCSItems = (List<Teesc07Subcstitem>) this
                .getSubCSItems();
        this.setSubCostStrItemSelected((Teesc07Subcstitem) subCSItems
                .get(Integer.parseInt(key) - 1));
    }
    
    public void setEvolveFromSelMapped(String key, String value) {
    	List<Teesc07Subcstitem> subCSItems = (List<Teesc07Subcstitem>) this
    	.getSubCSItems();
    	this.setSubCostStrItemSelected((Teesc07Subcstitem) subCSItems
    			.get(Integer.parseInt(key) - 1));
//    	((Teesc07Subcstitem)(((List)this.subCSItems).get(Integer.parseInt(key) - 1))).setEvolveFromSel(value);
    }
    
	public String getEvolveFromSelMapped(){
		return "-1";
	}

    public void setSubCSItemNVMapped(String key, String value) {
        List<Teesc07Subcstitem> subCSItemsNV = (List<Teesc07Subcstitem>) this
                .getSubCSItemsNV();
        this.setSubCostStrItemNVSelected((Teesc07Subcstitem) subCSItemsNV
                .get(Integer.parseInt(key) - 1));
    }

    public void setSubCSMapped(String key, String value) {
        List<Teesc03Subcoststr> subCostStructures = (List<Teesc03Subcoststr>) this
                .getSubCostStructures();
        this.setSubCostStrSelected((Teesc03Subcoststr) subCostStructures
                .get(Integer.parseInt(key) - 1));
    }

    public Stack<Teesc03Subcoststr> getHierarchy() {
        return hierarchy;
    }

    public void setHierarchy(Stack<Teesc03Subcoststr> hierarchy) {
        this.hierarchy = hierarchy;
    }

    public String getEnableComboEconomicIndex() {
        return enableComboEconomicIndex;
    }

    public void setEnableComboEconomicIndex(String enableComboEconomicIndex) {
        this.enableComboEconomicIndex = enableComboEconomicIndex;
    }

    public ActionErrors validate(ActionMapping mapping,
                                 HttpServletRequest request) {
        ActionErrors ae = new ActionErrors();
        MessageResources resources = (MessageResources) request
                .getAttribute(org.apache.struts.Globals.MESSAGES_KEY);

        if ("addUpdateItem".equals(this.getSection())) {
            if (this.getItemCategorySel().equals("-1")) {
                ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                        "error.noSelected.m", resources
                                .getMessage("costStructure.itemCategory")));
            }
            if (this.getItemSel() == null || this.getItemSel().equals("-1")) {
                ae.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(
                        "error.noSelected.m", resources
                                .getMessage("costStructure.item")));
            }
            if (this.getSubCostStrItemSelected() != null
                    && this.getEconomicIndexSel().equals("-1")) {
                ae
                        .add(
                                ActionMessages.GLOBAL_MESSAGE,
                                new ActionMessage(
                                        "error.noSelected.m",
                                        resources
                                                .getMessage("costStructure.def.label.economicIndex")));
            }
            if (StringUtils.isBlank(this.getCompItem())) {
                ae
                        .add(
                                ActionMessages.GLOBAL_MESSAGE,
                                new ActionMessage(
                                        "costStructure.def.error.composicionPercentageCantBeNull"));
            } else {
                try {
                    Double d = Double.valueOf(this.getCompItem());
                    if (d.doubleValue() > 100) {
                        ae
                                .add(
                                        ActionMessages.GLOBAL_MESSAGE,
                                        new ActionMessage(
                                                "costStructure.def.error.composicionPercentageGtHundred"));
                    }
                } catch (Exception e) {
                    ae
                            .add(
                                    ActionMessages.GLOBAL_MESSAGE,
                                    new ActionMessage(
                                            "costStructure.def.error.invalidComposicionPercentage"));
                }
            }
        } else if ("addUpdateSubCs".equalsIgnoreCase(this.getSection())) {
            if (StringUtils.isBlank(this.getSubCsName())) {
                ae
                        .add(
                                ActionMessages.GLOBAL_MESSAGE,
                                new ActionMessage(
                                        "costStructure.def.error.requiredSubCostStructureName"));
            }
            if (StringUtils.isBlank(this.getCompSubCs())) {
                ae
                        .add(
                                ActionMessages.GLOBAL_MESSAGE,
                                new ActionMessage(
                                        "costStructure.def.error.composicionPercentageCantBeNull"));
            } else {
                try {
                    Double d = Double.valueOf(this.getCompSubCs());
                    if (d.doubleValue() > 100) {
                        ae
                                .add(
                                        ActionMessages.GLOBAL_MESSAGE,
                                        new ActionMessage(
                                                "costStructure.def.error.composicionPercentageGtHundred"));
                    }
                } catch (Exception e) {
                    ae
                            .add(
                                    ActionMessages.GLOBAL_MESSAGE,
                                    new ActionMessage(
                                            "costStructure.def.error.invalidComposicionPercentage"));
                }
            }
        } else if ("viewMacropartInfo".equalsIgnoreCase(this.getSection())) {

            // Que elija linea de vehiculo.
            if (this.getVehicleLineSel() == null
                    || this.getVehicleLineSel().equals("-1")) {
                ae
                        .add(
                                ActionMessages.GLOBAL_MESSAGE,
                                new ActionMessage(
                                        "error.noSelected.m",
                                        resources
                                                .getMessage("costStructure.def.label.vehicleLine")));
            }
            // Verifico y formateo la Mix Date
            if (StringUtils.isBlank(this.getMixYear())) {
                ae
                        .add(
                                ActionMessages.GLOBAL_MESSAGE,
                                new ActionMessage(
                                        "errors.required",
                                        resources
                                                .getMessage("costStructure.def.label.mixDate")));
            } 
        } else if ("fullEconomics".equalsIgnoreCase(this.getSection())) {

            //Que elija linea de vehiculo.
            if (this.getVehicleLineSel() == null
                    || this.getVehicleLineSel().equals("-1")) {
                ae
                        .add(
                                ActionMessages.GLOBAL_MESSAGE,
                                new ActionMessage(
                                        "error.noSelected.m",
                                        resources
                                                .getMessage("costStructure.def.label.vehicleLine")));
            }
            // Verifico y formateo la Mix Date
            if (StringUtils.isBlank(this.getMixYear())) {
                ae
                        .add(
                                ActionMessages.GLOBAL_MESSAGE,
                                new ActionMessage(
                                        "errors.required",
                                        resources
                                                .getMessage("costStructure.def.label.mixDate")));
            } 
            // Que seleccione Evolve From
            if (StringUtils.isBlank(this.getEvolveFromYear())) {
                ae
                        .add(
                                ActionMessages.GLOBAL_MESSAGE,
                                new ActionMessage(
                                        "errors.required",
                                        resources
                                                .getMessage("costStructure.def.label.evolveFromYear")));
            } else {
                try{
                    if(Integer.valueOf(this.getEvolveFromYear())<0)
                        ae
                        .add(
                                ActionMessages.GLOBAL_MESSAGE,
                                new ActionMessage(
                                        "errors.year",
                                        resources
                                                .getMessage("costStructure.def.label.evolveFromYear")));
                } catch (Exception e) {
                    ae
                    .add(
                            ActionMessages.GLOBAL_MESSAGE,
                            new ActionMessage(
                                    "errors.year",
                                    resources
                                            .getMessage("costStructure.def.label.evolveFromYear")));
                }
            }
            // Que seleccione Evolve To
            if (StringUtils.isBlank(this.getEvolveToYear())) {
                ae
                        .add(
                                ActionMessages.GLOBAL_MESSAGE,
                                new ActionMessage(
                                        "errors.required",
                                        resources
                                                .getMessage("costStructure.def.label.evolveToYear")));
            } else {
                try{
                    if(Integer.valueOf(this.getEvolveToYear())<0)
                        ae
                        .add(
                                ActionMessages.GLOBAL_MESSAGE,
                                new ActionMessage(
                                        "errors.year",
                                        resources
                                                .getMessage("costStructure.def.label.evolveToYear")));
                } catch (Exception e) {
                    ae
                    .add(
                            ActionMessages.GLOBAL_MESSAGE,
                            new ActionMessage(
                                    "errors.year",
                                    resources
                                            .getMessage("costStructure.def.label.evolveToYear")));
                }
            }
        }

        return ae;
    }

    /**
     * 
     * @param num
     * @return
     */
    private BigDecimal getFormattedBigDecimal(String num) {
        DecimalFormat format = new DecimalFormat("0.00000");
        BigDecimal ret = null;
        double value = 0;

        try {
            value = format.parse(num).doubleValue();
            ret = new BigDecimal(value);
        } catch (ParseException e) {
            e.printStackTrace();
        }

        // return ret;
        return new BigDecimal(num);
    }

    /**
     * 
     * @return
     */
    public Teesc03Subcoststr getSubCostStructureForCreate() {
        Teesc03Subcoststr subCostStr = new Teesc03Subcoststr();

        subCostStr.setEesc03SubcstNameN(this.getSubCsName().trim());
        subCostStr.setEesc03SubcstPercentP(new BigDecimal(this.getCompSubCs()));
        return subCostStr;
    }

    /**
     * 
     * @return
     */
    public Teesc07Subcstitem getSubCostStrItemForCreate() {
        Teesc07Subcstitem subCostStrItem = new Teesc07Subcstitem();

        subCostStrItem.setEesc07ScstitmPercentP(new BigDecimal(this
                .getCompItem()));
        subCostStrItem.setTeesc03Subcoststr(this.getHierarchy().lastElement());
        return subCostStrItem;
    }

    /**
     * 
     * @return
     */
    public Teesc03Subcoststr getSubCostStructureForUpdate() {
        Teesc03Subcoststr subCostStr = this.getSubCostStrSelected();

        subCostStr.setEesc03SubcstNameN(this.getSubCsName().trim());
        subCostStr.setEesc03SubcstPercentP(new BigDecimal(this.getCompSubCs()));
        return subCostStr;
    }

    /**
     * 
     * 
     */
    public void setSubCostStrUpdateFields() {
        Teesc03Subcoststr subCostStr = this.getSubCostStrSelected();

        this.setSubCsName(subCostStr.getEesc03SubcstNameN());
        this.setCompSubCs(subCostStr.getEesc03SubcstPercentP().toString());
    }

    /**
     * 
     * 
     */
    public void setSubCostStrItemUpdateFields() {
        Teesc07Subcstitem subCostStrItem = this.getSubCostStrItemSelected();

        this
                .setItemCategorySel(subCostStrItem.getTeesc06Item()
                        .getTeesc05Itemcatgry().getEesc05ItemcatgryNumberK()
                        .toString());
        this.setItemSel(subCostStrItem.getTeesc06Item().getEesc06ItemNumberK()
                .toString());
        this.setCompItem(subCostStrItem.getEesc07ScstitmPercentP().toString());
        this.setEconomicIndexSel(subCostStrItem.getTeese01Economic()
                .getEese01EconNumberK().toString());
        this.setEnableComboEconomicIndex("true");
    }

    /**
     * 
     * @return
     */
    public Teesc07Subcstitem getSubCostStrItemForUpdate() {
        Teesc07Subcstitem subCostStrItem = null;

        if (this.getSubCostStrItemSelected() != null) { // analizar
            subCostStrItem = this.getSubCostStrItemSelected();
        } else {
            subCostStrItem = this.getSubCostStrItemNVSelected();
        }
        subCostStrItem.setEesc07ScstitmPercentP(new BigDecimal(this
                .getCompItem()));
        return subCostStrItem;
    }

    /**
     * 
     * 
     */
    public void setSubCostStrItemNVUpdateFields() {
        Teesc07Subcstitem subCostStrItem = this.getSubCostStrItemNVSelected();

        this
                .setItemCategorySel(subCostStrItem.getTeesc06Item()
                        .getTeesc05Itemcatgry().getEesc05ItemcatgryNumberK()
                        .toString());
        this.setItemSel(subCostStrItem.getTeesc06Item().getEesc06ItemNumberK()
                .toString());
        this.setCompItem(subCostStrItem.getEesc07ScstitmPercentP().toString());
        this.setEconomicIndexSel("-1");
        this.setEnableComboEconomicIndex(null);
    }

    public String getEvolveFromSel() {
        return evolveFromSel;
    }

    public void setEvolveFromSel(String evolveFromSel) {
        this.evolveFromSel = evolveFromSel;
    }

    public String getEvolveToSel() {
        return evolveToSel;
    }

    public void setEvolveToSel(String evolveToSel) {
        this.evolveToSel = evolveToSel;
    }

    public String getVehicleLineSel() {
        return vehicleLineSel;
    }

    public void setVehicleLineSel(String vehicleLineSel) {
        this.vehicleLineSel = vehicleLineSel;
    }

    /**
     * 
     * @return
     */
    public Ncas012VehicleVw getVehicleLine() {
    	Ncas012VehicleVw vehicleLine = new Ncas012VehicleVw();

        vehicleLine.setCas012VehicleCodeC(this.getVehicleLineSel());
        return vehicleLine;
    }

    public String getMixDate() {
        return mixDate;
    }

    public void setMixDate(String mixDate) {
        this.mixDate = mixDate;
    }

    public String getEvolveFromYear() {
        return evolveFromYear;
    }

    public void setEvolveFromYear(String evolveFromYear) {
        this.evolveFromYear = evolveFromYear;
    }

    public String getEvolveToYear() {
        return evolveToYear;
    }

    public void setEvolveToYear(String evolveToYear) {
        this.evolveToYear = evolveToYear;
    }

    public String getMixYear() {
        return mixYear;
    }

    public void setMixYear(String mixYear) {
        this.mixYear = mixYear;
    }

    public String getEvolveFromType() {
        return evolveFromType;
    }

    public void setEvolveFromType(String evolveFromType) {
        this.evolveFromType = evolveFromType;
    }

    public String getEvolveToType() {
        return evolveToType;
    }

    public void setEvolveToType(String evolveToType) {
        this.evolveToType = evolveToType;
    }

	public String getActivacionNiveles() {
		return activacionNiveles;
	}

	public void setActivacionNiveles(String activacionNiveles) {
		this.activacionNiveles = activacionNiveles;
	}

	public String getEvolveFromTemp() {
		return evolveFromTemp;
	}

	public void setEvolveFromTemp(String evolveFromTemp) {
		this.evolveFromTemp = evolveFromTemp;
	}

	public String getEvolveFromYearTemp() {
		return evolveFromYearTemp;
	}

	public void setEvolveFromYearTemp(String evolveFromYearTemp) {
		this.evolveFromYearTemp = evolveFromYearTemp;
	}

	public String getEvolveToTemp() {
		return evolveToTemp;
	}

	public void setEvolveToTemp(String evolveToTemp) {
		this.evolveToTemp = evolveToTemp;
	}

	public String getEvolveToYearTemp() {
		return evolveToYearTemp;
	}

	public void setEvolveToYearTemp(String evolveToYearTemp) {
		this.evolveToYearTemp = evolveToYearTemp;
	}

	public Map<Teesc03Subcoststr, Collection<Teesc07Subcstitem>> getMapaNodosNiveles() {
		return mapaNodosNiveles;
	}

	public void setMapaNodosNiveles(
			Map<Teesc03Subcoststr, Collection<Teesc07Subcstitem>> mapaNodosNiveles) {
		this.mapaNodosNiveles = mapaNodosNiveles;
	}

	public String getCampoVacioAux() {
		return "";
	}

	public void setCampoVacioAux(String campoVacioAux) {
		this.campoVacioAux = "";
	}

    public void reset(ActionMapping mapping, HttpServletRequest request) {
        this.activacionNiveles = "false";

    }

	
}
